﻿// ==================================================
// Copyright 2014 (C) , dotLogix
// Author: Alexander Schill <alexander@schillnet.de>.
// ==================================================

namespace DotLogix {
    #region Using Directives
    using System.Windows;
    using System.Windows.Media;

    #endregion

    public class AutoSizePath : AutoSizeBase {
        private Brush _fill;
        private Geometry _geometry;
        private Pen _pen;
        private Brush _stroke;
        private double _strokeThickness;

        public Brush Fill {
            get { return _fill; }
            set {
                _fill = value;
                InvalidateMeasure();
                InvalidateVisual();
            }
        }

        public Brush Stroke {
            get { return _stroke; }
            set {
                _stroke = value;
                UpdatePen();
                InvalidateMeasure();
                InvalidateVisual();
            }
        }

        public double StrokeThickness {
            get { return _strokeThickness; }
            set {
                _strokeThickness = value;
                UpdatePen();
                InvalidateMeasure();
                InvalidateVisual();
            }
        }

        public Pen Pen { get; set; }

        public string Data {
            set {
                _geometry = Geometry.Parse(value);
                InvalidateMeasure();
                InvalidateVisual();
            }
        }
        protected override Size Content { get { return _geometry==null? Size.Empty:_geometry.Bounds.Size; } }

        private void UpdatePen() {
            if(_strokeThickness == 0 || _stroke == null)
                _pen = null;
            else
                _pen = new Pen(_stroke, _strokeThickness);
        }

        protected override void RenderContent(DrawingContext drawingContext) {
            drawingContext.DrawGeometry(_fill, _pen, _geometry);
        }
    }
}